package com.zg.core.base

import android.view.View
import androidx.navigation.Navigator
import androidx.navigation.fragment.FragmentNavigator
import androidx.navigation.fragment.NavHostFragment
import com.zg.core.R

/***
 * @Author:      zxd
 * @CreateDate:  2021/7/6 14:11
 * @Description:
 */
open class SHNavHostFragment : NavHostFragment() {

    override fun createFragmentNavigator(): Navigator<out FragmentNavigator.Destination?> {
        return SHFragmentNavigator(
            requireContext(), childFragmentManager,
            getContainerId()
        )
    }

    /***
     * 这里使用原来的id还是之后创建的都可以，没想明白
     * 获取的是id，name不同丝毫不会有影响...
     * @return
     */
    private fun getContainerId(): Int {
        val id = id
        return if (id != 0 && id != View.NO_ID) {
            id
        } else R.id.nav_host_fragment_container
    }
}